package com.spic.business.plan.inspection.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.spic.business.plan.inspection.domain.PlanInspection;
import com.spic.business.plan.inspection.domain.PlanInspectionHistory;
import com.spic.business.plan.inspection.service.IPlanInspectionService;
import com.spic.business.plan.inspection.service.impl.PlanInspectionServiceImpl;
import com.spic.business.plan.supplies.domain.PlanSupplies;
import com.spic.business.plan.supplies.domain.PlanSuppliesDto;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 应急物资检查Controller
 *
 * @author spic
 * @date 2021-10-28
 */
@RestController
@RequestMapping("/plan/inspection")

public class PlanInspectionController extends BaseController
{
    @Autowired
    private IPlanInspectionService planInspectionService;
    @Autowired
    private PlanInspectionServiceImpl planInspectionServiceImpl;
    /**
     * 查询应急物资检查列表
     */
    @PreAuthorize(hasPermi = "business/plan:inspection:list")
    @GetMapping("/list")
    public TableDataInfo list(PlanInspection planInspection)
    {
        startPage();
        List<PlanInspection> list = planInspectionService.selectPlanInspectionList(planInspection);
        return getDataTable(list);
    }
    @GetMapping("/lists")
    public AjaxResult lists(PlanSupplies planSupplies)
    {
            List<HashMap<String,String>> listMap = new ArrayList<>();
            List<PlanSupplies> list = planInspectionServiceImpl.selectTransfer(planSupplies);
            for(PlanSupplies num:list){
                HashMap<String,String> map = new HashMap<>();
                map.put("key",num.getId()+"");
                map.put("label",num.getMaterialName());
                listMap.add(map);
            }
            return AjaxResult.success(list);
    }
    //上次检查没有检查过的物资
    @GetMapping("/live")
    @ResponseBody
    public AjaxResult materialNameList(){
        List<PlanSuppliesDto> list= planInspectionServiceImpl.selectMater();
        return AjaxResult.success(list);
    }
    //上次检查过的物资
    @GetMapping("/lives")
    @ResponseBody
    public AjaxResult materialNameLists(){
        List<PlanInspection> list1 = planInspectionServiceImpl.selectMaterAll();
        return AjaxResult.success(list1);
    }

    //上次检查过的物资
    @GetMapping("/notice")
    @ResponseBody
    public AjaxResult notice(){
        planInspectionServiceImpl.noticeMSG();
        return AjaxResult.success();
    }


    /**
     * 导出应急物资检查列表
     */
    @PreAuthorize(hasPermi = "business/plan:inspection:export")
    @Log(title = "应急物资检查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanInspection planInspection) throws IOException
    {
        List<PlanInspection> list = planInspectionService.selectPlanInspectionList(planInspection);
        ExcelUtil<PlanInspection> util = new ExcelUtil<PlanInspection>(PlanInspection.class);
        util.exportExcel(response, list, "应急物资检查数据");
    }

    /**
     * 获取应急物资检查详细信息
     */
    @PreAuthorize(hasPermi = "business/plan:inspection:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(planInspectionService.selectPlanInspectionById(id));
    }


    /**
     * 查询应急物资检查记录列表
     */
    @GetMapping("/GetInspectionHistoryList")
    public TableDataInfo GetInspectionHistoryList(PlanInspectionHistory planInspectionHistory)
    {
        startPage();
        List<PlanInspectionHistory> list = planInspectionService.selectPlanInspectionHistoryList(planInspectionHistory);
        return getDataTable(list);
    }

    /**
     * 新增应急物资检查记录
     */
    @PostMapping("/addInspectionHistory")
    public AjaxResult addInspectionHistory(@RequestBody PlanInspectionHistory planInspectionHistory)
    {
        return toAjax(planInspectionService.insertPlanInspectionHistory(planInspectionHistory));
    }


    @PostMapping("/updateInspectionHistory")
    public AjaxResult updateInspectionHistory(@RequestBody PlanInspectionHistory planInspectionHistory)
    {
        return toAjax(planInspectionService.updateInspectionHistory(planInspectionHistory));
    }


    /**
     * 删除应急物资检查记录
     */

    @DeleteMapping("/InspectionHistory/{ids}")
    public AjaxResult removeInspectionHistory(@PathVariable Long[] ids)
    {
        return toAjax(planInspectionService.deleteInspectionHistoryByIds(ids));
    }


    /**
     * 获取应急物资检查详细信息
     */

    @GetMapping(value = "/InspectionHistory/{id}")
    public AjaxResult getInspectionHistoryInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(planInspectionService.getInspectionHistoryInfo(id));
    }


    /**
     * 新增应急物资检查
     */
    @PreAuthorize(hasPermi = "business/plan:inspection:add")
    @Log(title = "应急物资检查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanInspection planInspection)
    {
        return toAjax(planInspectionService.insertPlanInspection(planInspection));
    }




    /**
     * 修改应急物资检查
     */
    @PreAuthorize(hasPermi = "business/plan:inspection:edit")
    @Log(title = "应急物资检查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanInspection planInspection)
    {
        return toAjax(planInspectionService.updatePlanInspection(planInspection));
    }

    /**
     * 删除应急物资检查
     */
    @PreAuthorize(hasPermi = "business/plan:inspection:remove")
    @Log(title = "应急物资检查", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(planInspectionService.deletePlanInspectionByIds(ids));
    }
}
